package day01;
import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class DataProcessing {
    public static void main(String[] args) {
        List<Data> dataList = Arrays.asList(
                new Data("apple", 1,1,"美食"),
                new Data("banana", 1,1,"美食"),
                new Data("carrot", 1,2,"美状"),
                new Data("potato", 1,5,"美状"),
                new Data("meat", 1,5,""),
                new Data("fish", 1,7,"")
        );

        Map<String, List<Data>> dataMap = dataList.stream()
                .collect(Collectors.groupingBy(Data::getTagCategoryname));
        System.out.println(dataMap.toString());
        System.out.println("-----------");
        dataMap.forEach((tagCategory, dataListByTagCategory) -> {
            System.out.println("Tag category: " + tagCategory);
            System.out.println("Data list: ");
            dataListByTagCategory.forEach(data -> System.out.println(data.toString()));
            System.out.println();
        });
    }
}

class Data {
    private String name;
    private Integer id;
    private Integer tagCategory;
    private String tagCategoryname;

    public Data(String name, Integer id, Integer tagCategory, String tagCategoryname) {
        this.name = name;
        this.id = id;
        this.tagCategory = tagCategory;
        this.tagCategoryname = tagCategoryname;
    }

    public String getName() {
        return name;
    }

    public Integer getId() {
        return id;
    }

    public Integer getTagCategory() {
        return tagCategory;
    }

    public String getTagCategoryname() {
        return tagCategoryname;
    }

    @Override
    public String toString() {
        return "Data{" +
                "name='" + name + '\'' +
                ", id=" + id +
                ", tagCategory=" + tagCategory +
                ", tagCategoryname='" + tagCategoryname + '\'' +
                '}';
    }
}